/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vue.structure;

import entityprojet.Journaux;
import entityprojet.JournauxJpaController;
import entityprojet.Taxe;
import entityprojet.TaxeJpaController;
import entityprojet.Typejo;
import entityprojet.TypetaxeJpaController;
import java.util.List;
import javax.swing.JOptionPane;
import outils.Outils;

/**
 *
 * @author T.Ron
 */
public class CompteJournaux extends javax.swing.JFrame {
    private Journaux journal;

    /**
     * Creates new form CompteAnalytique
     */
    public CompteJournaux() {
        initComponents();
    }

    CompteJournaux(Journaux tmp) {
          this.journal = tmp;
          initComponents();
          RemplirChamp();
    }

    public void RemplirChamp(){
        code.setText(journal.getCodejo());
        intitule.setText(journal.getIntitulejo());
        for(int i=0;i<Outils.listeJournaux().length;i++){
             if(Outils.listeJournaux()[i].split("-")[0].trim().equals((""+journal.getTypejo().getIdTypejo()).trim())){
                type.setSelectedIndex(journal.getTypejo().getIdTypejo()-1);
             }
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        code = new javax.swing.JTextField();
        intitule = new javax.swing.JTextField();
        type = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        saisie = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        saisie1 = new javax.swing.JCheckBox();
        saisie2 = new javax.swing.JCheckBox();
        comptet = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Compte Analytique");

        jLabel1.setText("Code :");
        jLabel1.setToolTipText("");

        jLabel2.setText("Intitulé :");

        jLabel4.setText("Compte trésorerie");

        intitule.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                intituleActionPerformed(evt);
            }
        });

        String[] blop  ={"t","b","c"};
        type.setModel(new javax.swing.DefaultComboBoxModel(Outils.listeTypeJournal()));
        type.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                typeActionPerformed(evt);
            }
        });

        jButton1.setText("Ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Annuler");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        saisie.setText("Saisie analytique");
        saisie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saisieActionPerformed(evt);
            }
        });

        jLabel5.setText("Type :");
        jLabel5.setToolTipText("");

        saisie1.setText("Contrepartie à chauqe ligne");
        saisie1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saisie1ActionPerformed(evt);
            }
        });

        saisie2.setText("Mise en sommeil");
        saisie2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saisie2ActionPerformed(evt);
            }
        });

        comptet.setModel(new javax.swing.DefaultComboBoxModel(blop));
        comptet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comptetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(saisie2)
                    .addComponent(saisie1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(comptet, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jLabel2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(intitule, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(code, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(type, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton2))))
                    .addComponent(saisie))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(code, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(intitule, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(saisie)
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(comptet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(saisie1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(saisie2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         // TODO add your handling code here:
         JournauxJpaController cjc = new JournauxJpaController ();
         boolean trouve = false;
         /*  List<Typejo> lcomptea = cjc.findTaxeEntities();
         boolean trouve = false;
         for(int i=0;i<lcomptea.size();i++){
            if(lcomptea.get(i).getIdTaxe().equals(Integer.parseInt(code.getText().trim())))
                trouve = true;
         }
         */
         if(!trouve){
            Journaux ca = new Journaux(cjc.findJournauxEntities().size()+1,code.getText(),intitule.getText(),new Typejo(Integer.parseInt(type.getModel().getSelectedItem().toString().substring(0,1))));
            cjc.create(ca);
            JOptionPane.showMessageDialog(null,"Enregistrement effectué avec succès !!!");
         }
         else{
             JOptionPane.showMessageDialog(null,"Ce numéro existe déjà dans la base !!!");
         }
         
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void saisieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saisieActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_saisieActionPerformed

    private void typeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_typeActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_typeActionPerformed

    private void saisie1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saisie1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_saisie1ActionPerformed

    private void saisie2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saisie2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_saisie2ActionPerformed

    private void intituleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_intituleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_intituleActionPerformed

    private void comptetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comptetActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comptetActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CompteJournaux.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CompteJournaux.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CompteJournaux.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CompteJournaux.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CompteJournaux().setVisible(true);
            }
        });
    }
    private Taxe taxe;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField code;
    private javax.swing.JComboBox comptet;
    private javax.swing.JTextField intitule;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JCheckBox saisie;
    private javax.swing.JCheckBox saisie1;
    private javax.swing.JCheckBox saisie2;
    private javax.swing.JComboBox type;
    // End of variables declaration//GEN-END:variables
}
